﻿using BLL.Utility;
using Entity.Context;
using Entity.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL.Sgf
{
    public sealed class DespesaBLL : AbstractClass
    {

        #region -- Salvar --
        public void Salvar(Despesa pEntity)
        {
            try
            {
                Valida(pEntity);
                using (var ctx = new Context())
                {
                    ctx.Despesa.Add(pEntity);
                    ctx.SaveChanges();
                }
            }
            catch (EValidationException evx)
            {
                throw new EValidationException(evx.Message);
            }
            catch (Exception ex)
            {
                throw new Exception("DespesaBLL.Salvar :: " + ex.Message, ex);
            }
        }
        #endregion

        #region -- Valida --
        private static void Valida(Despesa pEntity)
        {
            if (pEntity.CategoriaDespesaId == 0)
                throw new EValidationException("Tipo Despesa é obrigatório");
        }
        #endregion

    }
}
